{{ define "banner-img" }}
    <img class="banner-img" src="{{ . }}" loading="lazy"/>
{{ end }}

{{ define "banner-info-icon" }}
<div class="banner-info">
    <a class="banner-info-icon" type="button" href="{{ . }}" target="_blank">
        {{ partial "helper/icon" "info" }}
    </a>
</div>
{{ end }}

<div class="banner-container">
    {{ with .Site.Params.banner }}
        <div class="banner-info">
            {{ if .info }}
                <span class="banner-info-text">{{ .info }}</span>
            {{ end }}
        </div>

        {{ if .wallhaven.enabled }}
            {{ with .wallhaven }}
                {{ $urlPre := "https://wallhaven.cc/api/v1/collections/" }}
                {{ $url := (printf "%v/%v" .username .collection_id) }}
                {{ $data_images := getJSON $urlPre $url }}
                {{ with $data_images }}
                    {{ $total := sub .meta.total 1 }}
                    {{ $list := shuffle (seq 0 $total) }}
                    {{ $val := index $list 0 }}
                    {{ $info := index .data $val }}
                    {{if $info.path}}
                        {{ template "banner-info-icon" $info.short_url}}
                        {{ template "banner-img" $info.path }}
                    {{ end }}
                {{ end }}
            {{ end }}
        {{ else }}
            {{ if .local.enabled }}
                {{ with .local }}
                    {{ if .src }}
                        {{ template "banner-info-icon" .url}}
                        {{ template "banner-img" .src }}
                    {{ end }}
                {{ end }}
            {{ else }}
                {{ template "banner-info-icon" ""}}
                {{ template "banner-img" "img/default.jpg" }}
            {{ end }}
        {{ end }}
    {{ end }}
</div>